package com.starsea.book.ui.newpage

import android.os.Bundle
import androidx.activity.viewModels
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
import com.starsea.book.base.VMBaseActivity
import com.starsea.book.databinding.ActivityMyWalletBinding
import com.starsea.book.ui.newpage.adapter.MyPagerAdapter
import com.starsea.book.ui.newpage.viewmodel.WalletViewModel
import com.starsea.book.utils.viewbindingdelegate.viewBinding


/**
 * @author Lee
 * @createTime 2024-02-22 14 GMT+8
 * @desc : 我的钱包
 */
class MyWalletActivity : VMBaseActivity<ActivityMyWalletBinding, WalletViewModel>() {

    override val binding by viewBinding(ActivityMyWalletBinding::inflate)
    override val viewModel by viewModels<WalletViewModel>()
    val mFragments: MutableList<Fragment> = ArrayList()

    var myPagerAdapter: MyPagerAdapter? = null

    val listTitle: MutableList<String> = ArrayList()

    var index = 0


    override fun onActivityCreated(savedInstanceState: Bundle?) {
        listTitle.clear()
        mFragments.clear()

        listTitle.add("")
//        listTitle.add("")
        mFragments.add(WalletCoinFragment.newInstance())
//        mFragments.add(WalletCashFragment.newInstance())

        if (myPagerAdapter == null)
            myPagerAdapter = MyPagerAdapter(supportFragmentManager, mFragments, listTitle)

        binding.vpContent.offscreenPageLimit = listTitle.size
        binding.vpContent.adapter = myPagerAdapter


        binding.vpContent.addOnPageChangeListener(object : OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                binding.rtvOne.isSelected = position == 0
                binding.rtvTwo.isSelected = position == 1
            }

            override fun onPageScrollStateChanged(state: Int) {
            }

        })

        binding.rtvOne.setOnClickListener {
            binding.vpContent.currentItem = 0
        }

        binding.rtvTwo.setOnClickListener {
            binding.vpContent.currentItem = 1
        }

    }


}